<?php
    $search_params = !empty($this->extra_values['search_params'])?$this->extra_values['search_params']:array('keyword' => null, 'status' => null);
?>

<div class="carts_control">
    <a href="javascript:performActionSelectCart('<?php echo $this->url(array_merge(array('action' => 'mark', 'to_status' => Core_Model_DbTable_Carts::STATUS_DELETE), $search_params))?>')" 
       title="<?php echo $this->translate('TOOLTIP_STATUS_DELETE')?>" id="btn_delete">
           <?php echo $this->translate('LABEL_ACTION_DELETE')?>
    </a>
    <a href="javascript:performActionSelectCart('<?php echo $this->url(array_merge(array('action' => 'mark', 'to_status' => Core_Model_DbTable_Carts::STATUS_UNREAD), $search_params))?>')" 
       title="<?php echo $this->translate('TOOLTIP_STATUS_UNREAD')?>" id="btn_unread">
           <?php echo $this->translate('LABEL_ACTION_UNREAD')?>
    </a>
    <a href="javascript:performActionSelectCart('<?php echo $this->url(array_merge(array('action' => 'mark', 'to_status' => Core_Model_DbTable_Carts::STATUS_READ), $search_params))?>')" 
       title="<?php echo $this->translate('TOOLTIP_STATUS_READ')?>" id="btn_read">
           <?php echo $this->translate('LABEL_ACTION_READ')?>
    </a>
    <a href="javascript:performActionSelectCart('<?php echo $this->url(array_merge(array('action' => 'mark', 'to_status' => Core_Model_DbTable_Carts::STATUS_RESOLVED), $search_params))?>')" 
       title="<?php echo $this->translate('TOOLTIP_STATUS_RESOLVED')?>" id="btn_resolved">
           <?php echo $this->translate('LABEL_ACTION_RESOLVE')?>
    </a>
</div>

<script type="text/javascript">
    var msg_confirm_delete_cart = '<?php echo $this->translate('MSG_CONFIRM_DELETE_CART')?>';
    var msg_confirm_delete_carts = '<?php echo $this->translate('MSG_CONFIRM_DELETE_CARTS')?>';
    
	function confirmDelete(url, message){
        var delete_expr = /to_status\/0/;
        if(delete_expr.test(url)){
            if(confirm(message)){
                return true;
            }else{
                return false;
            }
        }
        return true;
    }

	function performActionSelectCart(action_url)
    {
        var id_carts = $('.cbx_cart:checked').map(function(){
            return this.value;
        }).get().join(',');
        if(id_carts == ""){
            alert("<?php echo $this->translate('PLEASE_SELECT_CARTS')?>");
        }
        else if(confirmDelete(action_url, msg_confirm_delete_carts)){
            location.href= action_url + "/id_carts/" + id_carts;
        }
    }
    $(document).ready(function(){
        $("#chx_carts").change(function(){
            if($(this).attr("checked") == 'checked')
            {
                $('.cbx_cart').attr('checked', 'checked');
            }
            else
            {
                $('.cbx_cart').removeAttr('checked');
            }
        });
        
        $(".cart_action").change(function(){
            if(!confirmDelete($(this).val(), msg_confirm_delete_cart)){
                $(this).val("");
                return false;
            }
            else{
                location.href = $(this).val();
            }
        });
    });
</script>
